From 57e4258690eff791d8aafb1d0c1bbbda155b4207 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20Dre=C3=9Fler?= Date: Thu, 17 Mar 2022 17:08:33 +0100 Subject: [PATCH] Replace "long-press" of click action with ClutterLongPressGesture Nothing fancy here, just a straightforward replacement of one API with another. Part-of: --- js/ui/backgroundMenu.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/js/ui/backgroundMenu.js b/js/ui/backgroundMenu.js index 4b812b250..c88d1efc1 100644 --- a/js/ui/backgroundMenu.js +++ b/js/ui/backgroundMenu.js @@ -37,20 +37,21 @@ export function addBackgroundMenu(actor, layoutManager) { actor._backgroundMenu.open(BoxPointer.PopupAnimation.FULL); } - let clickAction = new Clutter.ClickAction(); - clickAction.connect('long-press', (action, theActor, state) => { - if (state === Clutter.LongPressState.QUERY) { - return (action.get_button() === 0 || - action.get_button() === 1) && - !actor._backgroundMenu.isOpen; - } - if (state === Clutter.LongPressState.ACTIVATE) { - let [x, y] = action.get_coords(); - openMenu(x, y); - actor._backgroundManager.ignoreRelease(); - } - return true; + const longPressGesture = new Clutter.LongPressGesture({ + required_button: Clutter.BUTTON_PRIMARY, }); + longPressGesture.connect('recognize', () => { + if (actor._backgroundMenu.isOpen) + return; + + const coords = longPressGesture.get_coords(); + const point = new Graphene.Point3D({x: coords.x, y: coords.y}); + const transformedPoint = actor.apply_transform_to_point(point); + openMenu(transformedPoint.x, transformedPoint.y); + }); + actor.add_action(longPressGesture); + + const clickAction = new Clutter.ClickAction(); clickAction.connect('clicked', action => { if (action.get_button() === 3) { let [x, y] = action.get_coords(); -- 2.39.5